<?php
// 本类由系统自动生成，仅供测试用途
class StoreAction extends Action {
	
    public function login(){
    	$phone=$_POST['phone'];
    	$password=$_POST['password'];
    	$store=M('store');
    	$where['phone']=$phone;
    	$where['password']=$password;
    	$rs=$store->where($where)->select();
    	if($rs){
    		$result['code']='1';
 			$result['msg']='登陆成功';
 			$result['store_info']=$rs;
    	}else{
    		$result['code']='0';
 			$result['msg']='用户名或密码不正常';
    	}
    	$this->ajaxReturn($result,'JSON');
    }
    
    public function setIsOpen()
    {
    	$store_id=$_POST['id'];
    	$is_open=$_POST['is_open'];
    	$store=M('store');
    	$where['id']=$store_id;
    	$option['is_open']=$is_open;
    	$rs=$store->where($where)->save($option);
    	if($rs!=false){
    		$result['code']='1';
 			$result['msg']='设置成功';
    	}else{
    		$result['code']='0';
 			$result['msg']='设置失败';
    	}
    	$this->ajaxReturn($result,'JSON');
    }
    public function addStoreClass()
    {
    	$store_id=$_POST['id'];
    	$name=$_POST['name'];
    	$store_class=M('store_class');
    	$where['store_id']=$store_id;
    	$where['name']=$name;
    	$rs=$store_class->data($where)->add();
    	if($rs>0){
    		$result['code']='1';
 			$result['msg']='添加分类成功';
    	}else{
    		$result['code']='0';
 			$result['msg']='添加分类失败';
    	}
    	$this->ajaxReturn($result,'JSON');
    }
    public function storeClassList()
    {
    	$store_id=$_POST['id'];
    	$store_class=M('store_class');
    	$where['store_id']=$store_id;
    	$rs=$store_class->where($where)->select();
    	$this->ajaxReturn($rs,'JSON');
    }
    
    public function addStoreGoods()
    {
    	$store_id=$_POST['store_id'];
    	$class_id=$_POST['class_id'];
    	$name=$_POST['name'];
    	$price=$_POST['price'];
    	$storeGoods=M('store_goods');
    	$data['store_id']=$store_id;
    	$data['class_id']=$class_id;
    	$data['price']=$price;
    	$data['name']=$name;
    	$rs=$storeGoods->data($data)->add();
    	if($rs>0)
    	{
    		$result['code']='1';
 			$result['msg']='添加商品成功';
    	}
    	else
    	{
    		$result['code']='0';
 			$result['msg']='添加商品失败';
    	}
    	
    	$this->ajaxReturn($result,'JSON');
    }
    
    public function getGoodsByClass()
    {
    	$class_id=$_POST['class_id'];
    	$store_goods=M('store_goods');
    	$where['class_id']=$class_id;
    	$list=$store_goods->where($where)->select();
    	$this->ajaxReturn($list,'JSON');
    }
    
    public function getOrderByStatus()
    {
    	$status=$_POST['status'];
    	$store_id=$_POST['store_id'];
    	$order=M('Orders');
    	$where['in_orders.status']=$status;
    	$where['in_orders.store_id']=$store_id;
    	$orderList=$order->field('in_orders.*,wb.name as name,wb.phone as phone')
    	->join('left join in_wbar wb on wb.id=in_orders.wbar_id')->where($where)->order('create_time desc')->select();
    	$this->ajaxReturn($orderList,'JSON');
    }
    public function getOrderDetailByOrder()
    {
    	$order_id=$_POST['order_id'];
    	$order_detail=M('ordersDetail');
    	$where['in_orders_detail.order_id']=$order_id;
    	$order_detail_list=$order_detail->field('in_orders_detail.*,o.create_time as create_time,o.status as status,s.name as name,s.price as price
    	')->join('left join in_orders o on o.order_id='.$order_id.'')->join('left join in_store_goods s on s.id=in_orders_detail.goods_id')->where($where)->select();
    	$this->ajaxReturn($order_detail_list,'JSON');
    }
    public function updateOrderByOrderId()
    {
    	$order_id=$_POST['order_id'];
    	$status=$_POST['status'];
    	$order=D('Orders');
    	$where['order_id']=$order_id;
    	$option['status']=$status;
    	$rs=$order->where($where)->save($option);
    	if(!$rs==false){
    		$result['code']='1';
 			$result['msg']='状态更新成功';
    	}else{
    		$result['code']='0';
 			$result['msg']='状态更新失败';
    	}
    	$this->ajaxReturn($result,'JSON');
    }
}
?>